//
//  orderDetailViewController.m
//  1243
//
//  Created by 杨森 on 16/5/15.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "orderDetailViewController.h"
#import "orderDetailFirstCell.h"
#import "orderDetailSecondCell.h"
#import "orderDetailThirdCell.h"

@interface orderDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)NSDictionary *orderDetailArray;

@end

@implementation orderDetailViewController

- (id)initWithOrderId:(NSDictionary *)orderId userId:(NSString *)userId orderStatus:(int)orderStatus
{
    if ((self = [super init])) {
    
        //        _userId = userId;
        _orderStatus = orderStatus;
        self.orderDetailArray = orderId;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"订单详情";
    [self addTableView];
 
}

- (void)addTableView
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    UITableView *detailTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WEITH, HEIGHT) style:UITableViewStyleGrouped];
    [self.view addSubview:detailTableView];
    detailTableView.delegate = self;
    detailTableView.dataSource = self;
  
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.section == 0) {
        static NSString *identifier= @"orderDetailFirstCell";
        orderDetailFirstCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"orderDetailFirstCell" owner:nil options:nil] lastObject];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        }
        cell.NameLabel.text = [NSString stringWithFormat:@"收货人 : %@",self.orderDetailArray[@"ReceivName"]];
      
        cell.addressLabel.text = [NSString stringWithFormat:@"收货地址 : %@",self.orderDetailArray[@"ReceivAddress"]];//
        
        cell.photoNumLabel.text = [NSString stringWithFormat:@"联系方式 : %@",self.orderDetailArray
                        [@"ReceivMobile"]];

         return cell;
    }else if (indexPath.section == 1){
        
        static NSString *identifier= @"orderDetailSecondCell";
        orderDetailSecondCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];

        
        if (cell==nil) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"orderDetailSecondCell" owner:nil options:nil] lastObject];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;

        }

        cell.storeNameLabel.text =[NSString stringWithFormat:@"%@",self.orderDetailArray[@"MerchantName"]];
        
        cell.pruductName.text = [NSString stringWithFormat:@"%@",self.orderDetailArray[@"ProductName"]];
        
        cell.guiGeLabel.text = [NSString stringWithFormat:@"%@",self.orderDetailArray[@"NormsNames"]];
        
        cell.priceLabel.text = [NSString stringWithFormat:@"¥ %@",self.orderDetailArray[@"SellPrice"]];
        
        cell.NumLabel.text = [NSString stringWithFormat:@"x%@",self.orderDetailArray[@"Count"]];
        
        
        CGFloat total= [self.orderDetailArray[@"SellPrice"] floatValue] * [self.orderDetailArray[@"Count"] floatValue];
        cell.priceSecondLabel.text = [NSString stringWithFormat:@"¥ %.2f",total];
        
        
        
        cell.yunFeiLabel.text = @"实付款(含运费)";
        
        
        NSString *URLString = @"http://120.76.162.124:8083";
        
        NSString *PicString = [URLString stringByAppendingString:self.orderDetailArray[@"PictureURL"]];
        
        [cell.bgImage sd_setImageWithURL:[NSURL URLWithString:PicString]placeholderImage:[UIImage imageNamed:@"dress.png"]];
        
        return cell;

    }else {
        
        
        static NSString *identifier= @"orderDetailThirdCell";
        orderDetailThirdCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"orderDetailThirdCell" owner:nil options:nil] lastObject];
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;

        }
        
        cell.orderNumLabel.text = [NSString stringWithFormat:@"订单编号 : %@",self.orderDetailArray[@"OrderNO"]];
        
        
        if ([self.orderDetailArray[@"PayTime"] isEqual:[NSNull null]]) {
            
            cell.payTimeLabel.text = [NSString stringWithFormat:@"付款时间 : "];
        }else{
            NSString * payTimeLabel = [self.orderDetailArray[@"PayTime"] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
            cell.payTimeLabel.text = [NSString stringWithFormat:@"付款时间 : %@",payTimeLabel];

        }
        

        NSArray *DianArr = [self.orderDetailArray[@"CreateTime"] componentsSeparatedByString:@"."];
        NSString * createTimeStr = [DianArr[0] stringByReplacingOccurrencesOfString:@"T" withString:@" "];
        cell.createTime.text = [NSString stringWithFormat:@"创建时间 : %@",createTimeStr];
        
        return cell;
    }

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 60;
    }else if (indexPath.section== 1){
        return 190;
    }else{
        return 90;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 5;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}


/*
 ActualTotalPrice = 17;
 AddTime = "2016-05-16T09:45:01.817";
 AfterLessPrice = 0;
 AfterLessTotalPrice = "16.49";
 BasePrice = 15;
 BrandId = 76;
 Browser = "<null>";
 CanLessPrice = 0;
 Cangku = "<null>";
 CityId = 1372;
 Color = "<null>";
 CompanyId = "-1";
 CompanyId1 = "-1";
 CompanyId2 = "-1";
 CompanyId3 = "-1";
 CompanyId4 = "-1";
 ContactAddress = "\U676d\U5dde\U6587\U4e09\U8def90\U53f7 ";
 ContactEmail = "tets@163.com";
 ContactMobile = 13819128727;
 ContactName = test;
 ContactPassCode = 313309;
 ContactPhone = 8888888;
 Count = 1;
 CreateTime = "2016-05-16T09:45:01.817";
 CreateTime1 = "<null>";
 CreationDate = "2016-05-11T17:24:48";
 CuxiaoName = "<null>";
 ErrMsg = "<null>";
 GBCode = "<null>";
 GoodsTypeId = 11;
 IESProductId = 54584;
 IP = "61.130.4.18";
 Id = 2661;
 Id1 = 53034;
 Id2 = 53875;
 Id3 = 118726;
 Id4 = 1;
 IsActive = 1;
 IsCuXiao = "<null>";
 IsGift = 0;
 IsGroup = 0;
 IsGroup1 = 0;
 IsHasPart = 0;
 IsToDrp = 0;
 IsValid = 1;
 IsVouchers = 0;
 LessPersent = "<null>";
 Level = 0;
 LoginName = Service;
 LoginPassword = 123456;
 Logo = "/CkImages/Logo/m_logo1.jpg";
 Mac = "<null>";
 MarketPrice = "<null>";
 MerChantId = 1;
 MerchantName = "\U5317\U5927\U8352\U81ea\U7136\U90a8\U660e\U5eb7\U5546\U57ce";
 ModifiedDate = "2016-05-14T19:56:28.957";
 ModifierId = Service;
 NeedCardNum = 50;
 Norms1Code = 40761;
 Norms1Name = "250ml/\U76d2";
 Norms2Code = 40761;
 Norms2Name = "250ml/\U76d2";
 NormsDetailIds = "";
 NormsDetailNames = "";
 NormsIds = "3=40631;4=40630;";
 NormsNames = "\U5c3a\U5bf8=\U5747\U7801;\U989c\U8272=\U5747\U8272;";
 OSVersion = "<null>";
 OrderId = "<null>";
 OrderNO = UFQP20160516094501;
 OrderNO1 = UFQP20160516094501;
 OwnerId = Service;
 ParentMerchantId = 0;
 PayStatus = 0;
 PayTime = "<null>";
 PayType = "<null>";
 Pic = "<null>";
 PicPath = "<null>";
 PictureURL = "/CkImages/files/huanyagouwuquan.jpg";
 PictureUrl1 = "/CkImages/files/%e5%95%86%e5%93%81%e8%af%a6%e6%83%85/%e5%9b%be%e7%89%87/%e9%be%99%e4%b8%b9%e9%be%99%e4%b8%b9%e9%bb%91%e7%89%9b%e5%a5%b6250ml%e7%9b%92.jpg";
 Postion = 2;
 Price = 17;
 Price1 = 3980;
 ProductCode = "<null>";
 ProductCode1 = 00987654321;
 ProductCode2 = 6915276707406;
 ProductId = 54584;
 ProductName = "\U9f99\U4e39/\U9f99\U4e39\U9ed1\U725b\U5976/250ml/\U76d2";
 ProductType = "<null>";
 Property1 = 0;
 Property10 = 0;
 Property11 = "<null>";
 Property12 = "<null>";
 Property13 = "<null>";
 Property14 = "<null>";
 Property15 = "<null>";
 Property16 = "<null>";
 Property17 = "<null>";
 Property18 = "<null>";
 Property19 = "<null>";
 Property2 = 0;
 Property20 = "<null>";
 Property3 = 0;
 Property4 = 0;
 Property5 = 0;
 Property6 = 0;
 Property7 = 0;
 Property8 = 0;
 Property9 = 0;
 ProviceId = 1371;
 Remark = "<null>";
 Remark1 = "<null>";
 SKU = 6915276707406;
 SecurityStock = 9977;
 SellPrice = 17;
 SendStatus = 0;
 Size = "<null>";
 SkuId = "<null>";
 SkuNO = "<null>";
 Status = 0;
 Stauts = 0;
 StoreSite = "<null>";
 StoreSite1 = "<null>";
 TagName = "<null>";
 Title = "\U6d4b\U8bd5\U5546\U54c1001";
 TotalCount = "<null>";
 TotalPrice = 17;
 TotalPrice1 = 17;
 TypeId = 0;
 UpdateTime = "<null>";
 UserId = 6583;
 UserId1 = 6583;
 UserName = 123;
 UserName1 = 123;
 Weight = 1;
 lat = "120.121422";
 lot = "30.282391";
 
 */
@end
 

